package com.ies.dx.dex.file;

import java.io.DataInputStream;

import com.ies.dx.util.Hex;
import com.ies.dx.util.Input;

public class class_def_item extends dex_item
{
    /*file part*/
    private int class_idx;      //uint
    private int access_flags;   //uint
    private int superclass_idx; //uint
    private int interfaces_off; //uint
    private int source_file_idx; //uint
    private int annotations_off; //uint
    private int class_data_off;  //uint
    private int static_values_off; //uint
    
    /*data part*/
    private type_list interfaces;
    private class_data_item data;
    private annotations_directory_item annotations;
    private encoded_array_item static_values;

    public class_def_item(dex_file file)
    {
        super(file);
    }
    
    public void readData(Input dis)
    {
        try
        {
            if (interfaces_off != 0)
            {
                dis.moveCursorTo(interfaces_off);
                interfaces = new type_list(mFile);
                interfaces.read(dis);
            }
            
            if (annotations_off != 0)
            {
                dis.moveCursorTo(annotations_off);
                annotations = new annotations_directory_item(mFile);
                annotations.read(dis);
            }
            
            if (class_data_off != 0)
            {
                dis.moveCursorTo(class_data_off);
                data = new class_data_item(mFile);
                data.read(dis);
            }
            
            if (static_values_off != 0)
            {
                dis.moveCursorTo(static_values_off);
                static_values = new encoded_array_item(mFile);
                static_values.read(dis);
            }
            
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
    }

    public void read(Input dis)
    {
        try
        {
            class_idx = dis.readInt();
            access_flags = dis.readInt();
            superclass_idx = dis.readInt();
            interfaces_off = dis.readInt();
            source_file_idx = dis.readInt();
            annotations_off = dis.readInt();
            class_data_off = dis.readInt();
            static_values_off = dis.readInt();
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
    }

    public void show()
    {
        System.out.println("[class_idx]         :" + class_idx + " (0x" + Hex.u4(class_idx) + ")");
        System.out.println("[access_flags]      :" + access_flags + " (0x" + Hex.u4(access_flags) + ")");
        System.out.println("[superclass_idx]    :" + superclass_idx + " (0x" + Hex.u4(superclass_idx) + ")");        
        System.out.println("[interfaces_off]    :" + interfaces_off + " (0x" + Hex.u4(interfaces_off) + ")");        
        System.out.println("[source_file_idx]   :" + source_file_idx + " (0x" + Hex.u4(source_file_idx) + ")");        
        System.out.println("[annotations_off]   :" + annotations_off + " (0x" + Hex.u4(annotations_off) + ")");        
        System.out.println("[class_data_off]    :" + class_data_off + " (0x" + Hex.u4(class_data_off) + ")");        
        System.out.println("[static_values_off] :" + static_values_off + " (0x" + Hex.u4(static_values_off) + ")");        
    }

    public String getData() 
    {

        return null;
    }
}
